//
//  WDBaseViewController.m
//  testApp
//
//  Created by iMac on 2018/2/10.
//  Copyright © 2018年 iMac. All rights reserved.
//

#import "WDBaseViewController.h"


#define wdScreenWidth       [UIScreen mainScreen].bounds.size.width
#define wdScreenHeight      [UIScreen mainScreen].bounds.size.height
#define wdNavHeight         self.navigationController.navigationBar.frame.size.height
#define wdStatusBarHeight   [UIApplication sharedApplication].statusBarFrame.size.height
#define wdTabbarHeight      self.navigationController.navigationBar.frame.size.height

@interface WDBaseViewController ()

@property (nonatomic, weak) UIView *ground_view;
@property (nonatomic, assign) BOOL hasNav;
@property (nonatomic, assign) BOOL hasTab;

@end

@implementation WDBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupInitial];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
//- (void)viewSafeAreaInsetsDidChange {
//    [super viewSafeAreaInsetsDidChange];
//    [self setGroundViewframe:self.view hasNavBar:self.hasNav hasTabbar:self.hasTab];
//    NSLog(@"left: - %f", self.additionalSafeAreaInsets.left);
//    NSLog(@"right: - %f", self.additionalSafeAreaInsets.right);
//    NSLog(@"bottom: - %f", self.additionalSafeAreaInsets.bottom);
//    NSLog(@"top: - %f", self.additionalSafeAreaInsets.top);
//}




- (void)setGroundViewframe:(UIView *)view hasNavBar:(BOOL)hasNav hasTabbar:(BOOL)hasTab {
    if (@available(iOS 11, *)) {
        if ([view isKindOfClass:[UIScrollView class]]) {
            UIScrollView *scroll = (UIScrollView *)view;
            scroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
        }
    }
    else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat navHeight = self.navigationController.navigationBar.frame.size.height;
    CGFloat tabHeight = self.tabBarController.tabBar.frame.size.height;
    CGFloat statueHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
    y += statueHeight;
    if (hasNav) {
        y += navHeight;
        self.hasNav = hasNav;
    }
    CGFloat width = SCREEN_WIDTH;
    CGFloat height = SCREEN_HEIGHT - y;
    if (hasTab) {
        height -= tabHeight;
        self.hasTab = hasTab;
    }
    NSLog(@"navHeight--%f,,,tabHeight---%f", navHeight, tabHeight);
    NSLog(@"\nx-%f;\ny-%f;\nheight-%f;\nwidth-%f", x, y, height, width);
    view.frame = CGRectMake(x, 0, width, height);
}
- (void)setupInitial {
    self.hasNav = NO;
    self.hasTab = NO;
    // 设置所有返回按钮的文字为空
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]init];
    leftItem.title = @" ";
    self.navigationItem.backBarButtonItem = leftItem;
    //    [WZMAppInfoUtils checkNetwork:nil];
}

- (BOOL)shouldAutorotate {
    return NO;
}

- (void)dealloc {
//    WZMLog(@"关闭界面：%@", self.class);
    //    [SharedOrderManager removeDelegate:self];
}

@end
